using System;
using System.Collections;
using UnityEngine;
public class HeroPanel : BasePanel
{
	public UIGrid heroGrid;
	private GameObject heroItemPrb;
	public HeroManager heroManager{
		get{
			return (HeroManager)GameManager.GetInstatnce().GetManager(ManagerType.HERO);
		}
	}
	#region implemented abstract members of BasePanel
	public override IEnumerator Init ()
	{
		ResGameObject obj = new ResGameObject();
		yield return StartCoroutine(ResManager.GetInstance().Load("Prefabs/Items/HeroItem",obj));

		heroItemPrb = obj.obj as GameObject;
	}

	public override void Refresh ()
	{
		for(int i = 0;i < heroGrid.transform.childCount;i++){
			Transform obj = heroGrid.transform.GetChild(i);
			NGUITools.Destroy(obj.gameObject);
		}
		heroGrid.repositionNow = true;
		foreach(Hero hero in heroManager.GetHeroList()){
			if(hero != null){
				GameObject obj = NGUITools.AddChild(heroGrid.gameObject,heroItemPrb);
				obj.GetComponent<HeroItem>().SetItem(hero);
			}
		}
	}

	public override void Show ()
	{
		throw new NotImplementedException (); 
	}

	public override void Hide ()
	{
		throw new NotImplementedException ();
	}
	#endregion
	public void Back(){
		GameManager.GetInstatnce().ShowPanel(PanelName.MainMenuPanel);
	}
	
}


